import fix_path

from google.appengine.ext import webapp, deferred
from google.appengine.ext.webapp.util import run_wsgi_app 

from cleaner import *

import logging

class StatWiper(webapp.RequestHandler): 
    def get(self): 
        self.response.headers['Content-Type'] = 'text/html' 
        cleaner = StatWipeOuter()
        logging.info("StatWipeOuter start  = %s" % (str(cleaner)))
        deferred.defer(cleaner.run,500,1000)
        logging.info("StatWipeOuter end  = %s" % (str(cleaner)))
        pass

class HistWiper(webapp.RequestHandler): 
    def get(self): 
        self.response.headers['Content-Type'] = 'text/html' 
        cleaner = HistWipeOuter()
        logging.info("HistWipeOuter start  = %s" % (str(cleaner)))
        deferred.defer(cleaner.run,500,1000)
        logging.info("HistWipeOuter end  = %s" % (str(cleaner)))
        pass

class TmpStatWiper(webapp.RequestHandler): 
    def get(self): 
        self.response.headers['Content-Type'] = 'text/html' 
        cleaner = TmpStatWipeOuter()
        logging.info("TmpStatWipeOuter start  = %s" % (str(cleaner)))
        deferred.defer(cleaner.run,500,1000)
        logging.info("TmpStatWipeOuter end  = %s" % (str(cleaner)))
        pass

class TmpHistWiper(webapp.RequestHandler): 
    def get(self): 
        self.response.headers['Content-Type'] = 'text/html' 
        cleaner = TmpHistWipeOuter()
        logging.info("TmpHistWipeOuter start  = %s" % (str(cleaner)))
        deferred.defer(cleaner.run,500,100)
        logging.info("TmpHistWipeOuter end  = %s" % (str(cleaner)))
        pass

class MSAttachWiper(webapp.RequestHandler): 
    def get(self): 
        self.response.headers['Content-Type'] = 'text/html' 
        cleaner = MSAttachWipeOuter()
        logging.info("MSAttachWipeOuter start  = %s" % (str(cleaner)))
        deferred.defer(cleaner.run,500,100)
        logging.info("MSAttachWipeOuter end  = %s" % (str(cleaner)))
        pass


class HistoryOldWiper(webapp.RequestHandler): 
    def get(self): 
        self.response.headers['Content-Type'] = 'text/html' 
        cleaner = HistWipeOlder()
        cleaner.maxdate = datetime.strptime("2010-02-01","%Y-%m-%d").date()
        cleaner.delay = 5
        logging.info("HistWipeOlder start  = %s" % (str(cleaner)))
        deferred.defer(cleaner.run,500,1000)
        logging.info("HistWipeOlder end  = %s" % (str(cleaner)))
        pass

class Other(webapp.RequestHandler): 
    def get(self): 
        pass


application = webapp.WSGIApplication([('/cleaner/wipestat.*', StatWiper),
                                      ('/cleaner/wipehist.*', HistWiper),
                                      ('/cleaner/wipetmpstat.*', TmpStatWiper),
                                      ('/cleaner/wipetmphist.*', TmpHistWiper),
                                      ('/cleaner/MarketStatsAttach.*', MSAttachWiper),
                                      ('/cleaner/wipeoldhist.*', HistoryOldWiper),
                                      ('/cleaner/.*', Other)], debug=True) 

def main(): 
     run_wsgi_app(application) 

if __name__ == '__main__': 
     main() 